const http=require('http')
const fs=require('fs')
const path=require('path')

http.createServer((req,res)=>{
    if(req.url=='/'){
        var filePath=path.join(__dirname,'/get.html')
        var fileContent=fs.readFileSync('./get.html')
        res.writeHead(200,{"Content-Type":"text/html;charset=utf8"})
        res.write(fileContent)
        res.end()
    }
    else{
        // 获取请求url的信息
        var urlObj=new URL(req.url,'http://localhost:8081')
        // 提取？后面的参数
        var newsId=urlObj.searchParams.get('newsId')//1
        res.end('received request')
    }
    console.log(req.url)
}).listen(8081)